<template>
  <div>
    <!-- <h1 >用户注册</h1> -->
    <van-row>
      <van-col span="8"></van-col>
      <van-col span="8">
        <van-icon name="http://rul4y8e5f.hn-bkt.clouddn.com/%E6%B3%A8%E5%86%8C-%E5%A3%B9%E7%B1%B3%E6%BB%B4%E7%AD%94-01.png" size="5rem"></van-icon>
      </van-col>
      <van-col span="8"></van-col>
    </van-row>
    <van-form @submit="onRegister">
  <van-field
    v-model="tbUser.userNumber"
    name="账号"
    label="账号"
    placeholder="账号"
    :rules="[{ required: true, message: '请填写账号' }]"
  />
  <van-field
    v-model="tbUser.userPassword"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <van-field
    v-model="surePassword"
    type="password"
    name="确认密码"
    label="确认密码"
    placeholder="确认密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <van-field
    v-model="tbUser.userName"
    name="用户名"
    label="用户名"
    placeholder="用户名"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="tbUser.userPhone"
    name="电话号码"
    label="电话号码"
    placeholder="电话号码"
    :rules="[{ required: true, message: '请填写电话号码' }]"

  />
  <van-field
    v-model="tbUser.userEmail"
    name="邮箱"
    label="邮箱"
    placeholder="邮箱"
    :rules="[{ required: true, message: '请填写邮箱' }]"
    
  />



  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" >注册</van-button>
  </div>
</van-form>

  </div>
</template>

<script>
import UserAPI from '@/api/UserAPI';
import { Toast } from 'vant';
export default {
  name: 'userRegister',
  data() {
    return {
      tbUser:{
       userNumber: '',
       userPassword: '',
       userName: '',
       userPhone: '',
       userEmail: '',
       userIcon:'',
      },
      surePassword: '',
     

    };
  },
  methods: {
    onRegister() {
      this.register()
    },
    // 跳转回登录页面
    gotoLogin(){
      this.$router.push("/userLogin")
    },
    // 注册用户
    register(){
      if(this.surePassword===this.tbUser.userPassword){
      // 发送注册异步请求
      var result = UserAPI.UserRegistr2(this.tbUser)
      // 获取注册结果
        // 获取响应结果 
        result.then((val)=>{
        console.log(val)
        if(val.success){
              // 失败：提示
              Toast({
          message: '注册成功',
          position: 'bottom',
        });
          this.gotoLogin()
        }else{
           // 失败：提示
           Toast({
          message: val.errorMsg,
          position: 'bottom',
        });
        }
      })
    }else{
      Toast({
          message: '两次输入密码不一致',
          position: 'bottom',
        });
    }
    },

  },
}
</script>

<style lang="less">

</style>